package com.example.reactor.r2dbc.db.jdbc;

import com.example.reactor.r2dbc.db.Customer;
import jakarta.annotation.Resource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zpMeng
 * @since 6/16/2025
 */
@Service
public class JDBCService {

    @Resource
    private JdbcTemplate jdbcTemplate;

    public List<Customer> getCustomersByJDBC() {
        return jdbcTemplate.query(
                "select * from customer",
                (rs, rowNum) -> {
                    Customer customer = new Customer();
                    customer.setId(rs.getLong("id"));
                    customer.setFirstName(rs.getString("first_name"));
                    customer.setLastName(rs.getString("last_name"));
                    return customer;
                });
    }

}
